﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Management.Pipe
{
    /// <summary>
    /// A pipeitem, which sets all coefficients of a polynomial to zero.
    /// </summary>
    [Serializable]
    public class PolynomialSetToZeroPipeItem : AbstractPipeItem
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PolynomialSetToZeroPipeItem"/> class.
        /// </summary>
        public PolynomialSetToZeroPipeItem()
            : base()
        {
        }

        /// <summary>
        /// The method, which has to be overwrite to add interaction to a new pipeitem.
        /// </summary>
        /// <param name="workingItem">The working item.</param>
        /// <param name="index">The index.</param>
        public override void WorkOn(ref object workingItem, int index)
        {
            if (workingItem is Polynomial)
            {
                for (int i = 0; i < ((Polynomial) workingItem).Components.Count; i++)
                {
                    ((Polynomial) workingItem).Components[i].Coefficient = 0;
                }
            }
        }
    }
}